import { Checkbox } from "antd";

export const EditModuleColumns = [{
    title: '接口名称',
    dataIndex: 'name',
    key: 'name',
    width: 120,
    fixed: true
}, {
    title: '接口描述',
    dataIndex: 'description',
    key: 'description',
    width: 240
}, {
    title: '授权ID',
    dataIndex: 'value',
    key: 'value',
},
];

export const EditUserColumns = [
    {
        title: '登录名',
        dataIndex: 'loginName',
        key: 'loginName',
        width: 120,
        fixed: true
    },
    {
        title: '用户名称',
        dataIndex: 'userName',
        key: 'userName',
        wdith: 200,
        fixed: true
    },
    {
        title: '科普单位',
        dataIndex: 'company',
        key: 'company',
    }
];
export const editRightFormat = (data: any ) => {
    return {
        ...data,
        editable: /^[\d]+$/.test(data.editable) ? data.editable == 1 : data.editable,
        deleteable: /^[\d]+$/.test(data.deleteable) ? data.deleteable == 1 : data.deleteable,
        downloadable: /^[\d]+$/.test(data.downloadable) ? data.downloadable == 1 : data.downloadable
    };
};
export const EditMenuColumn = [
    {
        title: "页面名称",
        dataIndex: "name",
        width: 160,
        fixed: true,
        key: "title",
    }, {
        title: "页面路径",
        dataIndex: "pathname",
        key: "pathname"
    },
    {
        title: "编辑权限",
        dataIndex: "id",
        dataKey: "editable",
        render: (id: string, data: any, {
            rowChecked,
            setData,
            mapData
        }: any) => {
            const checkProps = rowChecked ? {} : { disabled: true };
            return <Checkbox {...checkProps} checked={editRightFormat(mapData || {})?.editable} onChange={(e) => {
                setData({
                    editable: e.target.checked
                });
            }} />
        }
    },
    {
        title: "删除权限",
        dataIndex: "id",
        dataKey: "deleteable",
        render: (id: string, data: any, {
            rowChecked,
            setData,
            mapData
        }: any) => {
            const checkProps = rowChecked ? {} : { disabled: true };
            return <Checkbox {...checkProps} checked={editRightFormat(mapData || {})?.deleteable} onChange={(e) => {
                console.log(mapData);
                setData({
                    deleteable: e.target.checked
                });
            }} />
        }
    },
    {
        title: "下载权限",
        dataIndex: "id",
        dataKey: "downloadable",
        render: (id: string, data: any, {
            rowChecked,
            setData,
            mapData
        }: any) => {
            const checkProps = rowChecked ? {} : { disabled: true };
            return <Checkbox {...checkProps} checked={editRightFormat(mapData || {})?.downloadable} onChange={(e) => {
                setData({
                    downloadable: e.target.checked
                });
            }} />
        }
    }
];